package figure8.GUI;

import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

import figure8.Controller;
import figure8.LoopTiming;
import figure8.Project;
import figure8.Network.Client;
import figure8.Network.Message;
import figure8.Network.Message.Type;

public class NetworkHostWindow extends JFrame {
	public NetworkHostWindow(final Controller controller) {
		super();
		
		final JFrame window = this;
		
		this.setLayout(new GridLayout(2, 2, 2, 2));
		
		this.add(new JLabel("Port"));
		final JTextField portField = new JTextField("8888");
		this.add(portField);
		this.setIconImage(Toolkit.getDefaultToolkit().getImage("src/figure8/GUI/Fig8-small.png"));
		this.setAlwaysOnTop(true);
		
		final JButton connect = new JButton("Host");
		connect.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {				
				int port = Integer.parseInt(portField.getText());
				
				controller.host(port);
				
				window.dispose();
			}
		});

		this.add(connect);

		this.pack();
		this.setVisible(true);
	}
} 
